package cn.afactory.tygz.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;

import com.tendcloud.tenddata.TCAgent;

import cn.afactory.tygz.R;
import cn.afactory.tygz.ui.base.BaseFragmentActivity;
import cn.afactory.tygz.ui.fragments.TopicAddFragment;

/**
 * Created by Kenneth on 15/9/17.
 */
public class TopicAddActivity extends BaseFragmentActivity {

    public final static String EXT_DATA_TAG = "tipicName";
    private TopicAddFragment mFragment;
    private String topicName;

    private int mPageIndex = 0;
    public void setPageIndex(int index) {
        mPageIndex = index;
    }

    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        return super.onCreateView(name, context, attrs);
    }

    @Override
    public void onResume() {
        super.onResume();
        TCAgent.onResume(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addTitleBar = false;

        Intent intent = getIntent();
        if (null != intent) {
            topicName = getIntent().getStringExtra(TopicAddActivity.EXT_DATA_TAG);
        } else {
            topicName = null;
        }
        setContentView(R.layout.ac_fragment);
        initview();
    }

    private void initview() {
        mFragment = new TopicAddFragment();
        if (mFragment != null) {
            if (!TextUtils.isEmpty(topicName)) {
                Bundle bundle = new Bundle();
                bundle.putString(TopicAddActivity.EXT_DATA_TAG, topicName);
                mFragment.setArguments(bundle);
            }
            addFragment(mFragment);
        } else {
            finish();
        }
    }

    private void addFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.fl_layout, fragment, "" + fragment.getClass())
                .commit();
    }
}
